<template>
	<view v-if="!loadding">
		<view v-if="listData.length > 0">
			<view class="address-list">
				<view class="address p-30-0 d-s-c border-b-d" v-for="(item, index) in listData" :key="index"
					style="margin: 0.16rem 0.25rem;border-radius: 0.2rem!important;background-color: #fff;    padding-right: 0.2rem;">

					<view class="info flex-1 ml20" @click="xzaddress(item)">
						<view class="">
							<view class="user f32">
								<text>{{ item.store_name }}</text>
								<text class="ml20 gray9 f26">{{ item.distance_unit }}</text>
							</view>
						</view>
						<view class="pt20 f26 gray3">
							<text class="icon iconfont icon-dizhi1"></text>
							<text style="margin-left: 5px;"> {{ item.address }}</text>
						</view>
						<view class="pt20 f26 gray3">
							<text class="icon iconfont icon-chakan"></text>
							<text style="margin-left: 5px;"> {{ item.shop_hours }}</text>
						</view>
					</view>
					<!-- <view class="icon-box plus d-c-c ml30" @click="delAddress(item.address_id)">
						<image class="add_icon_img" src="../../../static/icon/delete.png" mode="widthFix"></image>
					</view> -->
				</view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			/*是否加载完成*/
			loadding: true,
			indicatorDots: true,
			autoplay: true,
			interval: 2000,
			duration: 500,
			/*数据*/
			listData: [],
			/*默认地址id*/
			default_id: '0',
			options: {}
		}
	},
	onLoad: function (options) {
		this.options = newOptions;
	},
	onShow: function () {
		uni.showLoading({
			title: '加载中'
		});
		/*获取地址列表*/
		this.getData();
	},
	methods: {
		xzaddress(val) {
			console.log(val);
			uni.setStorageSync("storepickup", val);
			// console.log(uni.getStorageSync("address"));
			uni.showToast({
				title: '选择成功',
				duration: 1000
			});
			uni.navigateBack();
		},
		/*获取数据*/
		getData() {
			let self = this;
			let dataType = self.dataType;
			let options = {
				url: "",
				shop_supplier_id: self.options.id
			}
			if(self.options.longitude != undefined) {
				options.longitude = self.options.longitude
			}
			if(self.options.latitude != undefined) {
				options.latitude = self.options.latitude
			}
			console.log(options, 'ooppttiiooss');
			self._get('store.store/lists', options, function (res) {
				self.listData = res.data.list;
				self.default_id = res.data.default_id + '';
				self.loadding = false;
				uni.hideLoading();
			});
		},

		/*点击单选*/
		radioChange(e) {
			let self = this;
			self.default_id = e;
			self._post('user.address/setDefault', {
				address_id: e,
			}, function (res) {
				if (self.options.source === 'order') {
					// #ifndef H5
					uni.navigateBack();
					// #endif
					// #ifdef H5
					history.go(-1);
					// #endif
				}
			});
			return false;

		},

		/*编辑地址*/
		editAddress(e) {
			let delta = 1;
			if (this.options.source === 'order') {
				delta = 2;
			}
			this.gotoPage('/pages/user/address/edit/edit?address_id=' + e + '&delta=' + delta);
		},

		/*删除地址*/
		delAddress(e) {
			let self = this;
			wx.showModal({
				title: "提示",
				content: "您确定要移除当前收货地址吗?",
				success: function (o) {
					o.confirm && self._get('user.address/delete', {
						address_id: e
					}, function (result) {
						if (result.code == 1) {
							uni.showToast({
								title: '删除成功',
								duration: 2000
							});
							self.getData();
						}

					});
				}
			});

		}
	}
}
</script>

<style>
page {
	background-color: #F2F2F2;
}

.address-list {
	border-top: 16rpx solid #F2F2F2;
	padding: 0 20rpx;
	padding-bottom: 90rpx;
}

.foot-btns {
	padding: 0;
}

.foot-btns .btn-red {
	width: 100%;
	height: 90rpx;
	line-height: 90rpx;
	border-radius: 0;
}

.none_add {
	padding: 314rpx 214rpx 60rpx 214rpx;
}

.no_add {
	width: 322rpx;
	height: 180rpx;
}

.no_add_add {
	width: 320rpx;
	height: 80rpx;
	border: 2rpx solid #FFB7B7;
	border-radius: 40rpx;
	text-align: center;
	line-height: 80rpx;
	font-size: 32rpx;
	font-family: PingFang SC;
	font-weight: 500;
	color: #F6220C;
	margin: 0 auto;
}

.add_add {
	height: 64rpx;
	line-height: 64rpx;
	font-size: 26rpx;
	font-family: PingFang SC;
	font-weight: 500;
	color: #0777CD;
	padding: 0 35rpx;
	border-bottom: 1rpx solid #D9D9D9;
}

.defaul_add {
	padding: 9rpx 14rpx 10rpx 15rpx;
	background: #FFE7E4;
	font-size: 22rpx;
	font-family: PingFang SC;
	font-weight: 500;
	color: #F6220C;
}

.add_icon_img {
	width: 30rpx;
	height: 30rpx;
}

.none_line {
	width: 1rpx;
	height: 44rpx;
	background: #D9D9D9;
}
</style>